public abstract class Cerrada implements TablaDispersion {

	private Item[] diccionario = null;
	protected Dispersion disp;

	public Cerrada(int tamTabla, Dispersion disp) {
		diccionario = new Item[tamTabla];
		this.disp = disp;
	}

	protected abstract int funResolucionColision(int posIni, int numIntento);

	public Item buscar(String clave) {
		int i = 0;
		int posIni = disp.calcular(clave, this.dimension());
		int posActual = posIni;
		while (diccionario[posActual] != null && !diccionario[posActual].igualA(clave)) {
			i++;
			posActual = funResolucionColision(posIni, i) % this.dimension();
		}
		return diccionario[posActual];
	}

	public int insertar(Item x) {
		int posIni = disp.calcular(x.clave(), this.dimension());
		int colisions = 0;
		int posActual = posIni;
		
		if (buscar(x.clave()) != null) return 0;

		while (diccionario[posActual] != null) {
			posActual = funResolucionColision(posIni, ++colisions) % this.dimension();
		}
		diccionario[posActual] = x;
		return colisions;
	}

	public int dimension() {
		return diccionario.length;
	}

	public String listar() {
		String str = new String();
		str = str + "[";
		if (diccionario[0] != null)
			str += diccionario[0].clave();
		for (int i = 1; i < this.dimension(); i++)
			if (diccionario[i] != null)
				str = str + ";" + diccionario[i].clave();
			else
				str = str + ";";
		return (str + "]");
	}
}
